package com.study.lease.common.minio;

import io.minio.MinioClient;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 创建为配置类，将其注入到spring容器中，方便随时取用
 * description:构建minioClient客户端，和服务端进行交互，获取文件信息，上传文件，删除文件，下载文件等操作
 */
@Configuration
@ConfigurationPropertiesScan("com.study.lease.common.minio")
@ConditionalOnProperty(name = "minio.endpoint") // 判断是否开启minio配置
public class MinioConfiguration {
    @Autowired
    private MinioProperties minioProperties;
    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(minioProperties.getEndpoint())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                .build();
    }

}
